import request from '@/utils/request'

// 获取用户列表
export function getUserList(params = {}) {
  // 确保有默认分页参数
  const defaultParams = {
    page: 1,
    page_size: 100,
    ...params
  };
  
  return request({
    url: '/api/auth/list/',
    method: 'get',
    params: defaultParams
  })
}

// 获取用户详情
export function getUserDetail(id) {
  return request({
    url: `/api/auth/${id}/`,
    method: 'get'
  })
}

// 创建用户
export function createUser(data) {
  return request({
    url: '/api/auth/create/',
    method: 'post',
    data
  })
}

// 更新用户
export function updateUser(id, data) {
  return request({
    url: `/api/auth/update/${id}/`,
    method: 'put',
    data
  })
}

// 删除用户
export function deleteUser(id) {
  return request({
    url: `/api/auth/delete/${id}/`,
    method: 'delete'
  })
}

// 批量删除用户
export function batchDeleteUsers(ids) {
  return request({
    url: '/api/auth/batch-delete/',
    method: 'post',
    data: { ids }
  })
}

// 修改用户状态
export function changeUserStatus(id, status) {
  return request({
    url: `/api/auth/${id}/status/`,
    method: 'patch',
    data: { status }
  })
}

// 分配角色
export function assignRole(id, data) {
  return request({
    url: `/api/auth/${id}/role/`,
    method: 'patch',
    data
  })
}

// 获取用户统计数据
export function getUserStatistics() {
  return request({
    url: '/api/auth/statistics/',
    method: 'get'
  })
} 